﻿Imports System.Collections.ObjectModel
Imports System.ComponentModel

Public Class PictureView
    Implements INotifyPropertyChanged

    Private _index As Integer
    Private photos As ObservableCollection(Of Photo)

    Public Sub New(ByVal photos As ObservableCollection(Of Photo), ByVal index As Integer)
        Me.photos = photos
        _index = index
    End Sub

    Public ReadOnly Property AnyBefore() As Boolean
        Get
            Return _index > 0
        End Get
    End Property
    Public ReadOnly Property AnyMore() As Boolean
        Get
            Return _index < photos.Count - 1
        End Get
    End Property

    Public ReadOnly Property CurrentPhotoURL() As String
        Get
            Return photos(Index).ImageUrl
        End Get
    End Property

    Public Property Index() As Integer
        Get
            Return _index
        End Get
        Set(ByVal value As Integer)
            If value > photos.Count - 1 Then Throw New ArgumentException("Index cannot exceed count.")
            If value < 0 Then Throw New ArgumentException("Index cannot be less than 0.")
            _index = value
            OnPropertyChanged("CurrentPhotoURL")
            OnPropertyChanged("AnyBefore")
            OnPropertyChanged("AnyMore")
        End Set
    End Property

    Private Sub OnPropertyChanged(ByVal prop As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(prop))
    End Sub

    Public Event PropertyChanged(ByVal sender As Object, ByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged
End Class